package bb.lanxing.net.client;

import static bb.lanxing.manager.SharedManager.KEY_TOKEN;

import java.io.IOException;

import bb.lanxing.manager.SharedManager;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

//在请求头里添加token的拦截器处理
public class TokenHeaderInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        String token = SharedManager.getInstance().getString(KEY_TOKEN, "");
        Request originalRequest = chain.request();
        if (token.isEmpty()) {
            return chain.proceed(originalRequest);
        } else {
            //key的话以后台给的为准，我这边是叫token
            Request updateRequest = originalRequest.newBuilder().header("Authorization", token).build();
            return chain.proceed(updateRequest);
        }
    }
}